package com.tanhua.dubbo.api.mongo;

import com.tanhua.domain.mongo.TestResult;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@Service
public class TestResultApiImpl implements TestResultApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void save(TestResult result) {
        mongoTemplate.save(result);
    }

    @Override
    public TestResult findByReportId(String reportId) {
        Query query = new Query(Criteria.where("_id").is(reportId));

        return mongoTemplate.findOne(query,TestResult.class);
    }

    @Override
    public TestResult findByScore(Integer sum) {
        Query query = new Query(Criteria.where("score").is(sum));
        return mongoTemplate.findOne(query, TestResult.class);

    }
}
